export default {
	data() {
		return {
			mixinData: {
				name: '混入的data数据',
				value: 86
			}
		};
	},
	created() {
		console.log('混入的created生命周期');
	},

	methods: {
		changeMoneyToChinese(amount) {
			/* >--大小写转换方法--< */
			amount = parseFloat(amount)
			if (isNaN(amount)) {
				return
			} // || Math.abs(amount) > 99999999999.99
			amount = Math.round(amount * 100)
			var isInt = amount % 100 == 0 ? true : false
			var numArr = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']
			var unitArr = [
				'分',
				'角',
				'元',
				'拾',
				'佰',
				'仟',
				'万',
				'拾',
				'佰',
				'仟',
				'亿',
				'拾',
				'佰',
				'仟'
			]
			var resultStr = '',
				num,
				unitIdx,
				len,
				zeroCount = 0
			if (amount == 0) {
				return '零园整'
			}
			if (amount < 0) {
				resultStr += '负'
				amount = -amount
			}
			amount = amount.toString()
			len = amount.length
			for (var i = 0; i < len; i++) {
				num = parseInt(amount.charAt(i))
				unitIdx = len - 1 - i
				if (num == 0) {
					//元 万 亿 输出单位
					if (unitIdx == 2 || unitIdx == 6 || unitIdx == 11) {
						resultStr += unitArr[unitIdx]
						zeroCount = 0
					} else {
						zeroCount++
					}
				} else {
					if (zeroCount > 0) {
						resultStr += '零'
						zeroCount = 0
					}
					resultStr = resultStr + numArr[num] + unitArr[unitIdx]
				}
			}
			if (isInt) {
				resultStr += '整'
			}
			return resultStr
		},
		table_Header_Style({
			row,
			rowIndex
		}) { // 表头
			return {
				padding: '6.5px 4px 6.5px 4px !important',
				background: '#ECFFF5',
				color: 'black'
			}
		},
		cell_Style({
			row,
			clumn,
			rowIndex,
			columnIndex
		}) {
			const rainbowColor = n => { // 表驱动渲染单元格列的颜色
				const obj = {
					0: '#E1F5FF',
				}
				return obj[n] ? obj[n] : 'rgba(239,239,239,0.3)'
			}
			return {
				padding: '6.5px 4px 6.5px 4px !important',
				background: rainbowColor(columnIndex)
			}
		},
        moneyFormatter(key) {
            const formatMoney = (money, decimals = 2) => {
                return new Intl.NumberFormat("zh-CN", {
                    style: "currency",
                    currency: "CNY",
                    currencyDisplay: "symbol",
                    maximumFractionDigits: decimals,
                }).format(money);
            };
            var reg2 = new RegExp("¥")
            return formatMoney(key, 2).replace(reg2, "")
        },
		numSub(arg1, arg2) {
			// 浮点精度问题处理减法（arg1-arg2）
			var r1, r2, m, n
			try {
				r1 = arg1.toString().split('.')[1].length
			} catch (e) {
				r1 = 0
			}
			try {
				r2 = arg2.toString().split('.')[1].length
			} catch (e) {
				r2 = 0
			}
			m = Math.pow(10, Math.max(r1, r2)) //last modify by deeka //动态控制精度长度
			n = r1 >= r2 ? r1 : r2
			return ((arg1 * m - arg2 * m) / m).toFixed(n)
		},
		accMul(arg1, arg2) {
			// 乘法
			var m = 0,
				s1 = arg1.toString(),
				s2 = arg2.toString()
			try {
				m += s1.split('.')[1].length
			} catch (e) {}
			try {
				m += s2.split('.')[1].length
			} catch (e) {}
			return (
				(Number(s1.replace('.', '')) * Number(s2.replace('.', ''))) /
				Math.pow(10, m)
			)
		},
		numAdd(arg1, arg2) {
			// 浮点精度问题处理加法
			var r1, r2, m, c
			try {
				r1 = arg1.toString().split('.')[1].length
			} catch (e) {
				r1 = 0
			}
			try {
				r2 = arg2.toString().split('.')[1].length
			} catch (e) {
				r2 = 0
			}
			c = Math.abs(r1 - r2)
			m = Math.pow(10, Math.max(r1, r2))
			if (c > 0) {
				var cm = Math.pow(10, c)
				if (r1 > r2) {
					arg1 = Number(arg1.toString().replace('.', ''))
					arg2 = Number(arg2.toString().replace('.', '')) * cm
				} else {
					arg1 = Number(arg1.toString().replace('.', '')) * cm
					arg2 = Number(arg2.toString().replace('.', ''))
				}
			} else {
				arg1 = Number(arg1.toString().replace('.', ''))
				arg2 = Number(arg2.toString().replace('.', ''))
			}
			return (arg1 + arg2) / m
		},
        // 增加指定月份方法
        addMonth(yyyy_mm_dd, addMonthNum) { // 函数(开始日期,要增加的日期)
            // 先将字符串格式的时间类型转化为Date类型
            if (yyyy_mm_dd.length > 10) {
                var str = yyyy_mm_dd
            } else {
                var str = yyyy_mm_dd + ' 00:00:00';   //字符串格式的时间类型
            }
            var str1 = str.replace(/-/g, '/');   //'2018/01/01 00:00:00'
            var date = new Date(Date.parse(str1));   //date格式的时间类型

            //计算当前月最大天数
            Date.daysInMonth = function (year, month) {
                if (month == 1) {
                    if (year % 4 == 0 && year % 100 != 0)
                        return 29;
                    else
                        return 28;
                } else if ((month <= 6 && month % 2 == 0) || (month > 6 && month % 2 == 1))
                    return 31;
                else
                    return 30;
            };
            Date.prototype.addMonth = function (addMonth) {
                var y = this.getFullYear();
                var m = this.getMonth();
                var nextY = y;
                var nextM = m;
                //如果当前月+增加的月>11 这里之所以用11是因为 js的月份从0开始
                if ((m + addMonth) > 11) {
                    nextY = y + 1;
                    nextM = parseInt(m + addMonth) - 12;
                } else {
                    nextM = this.getMonth() + addMonth
                }
                var daysInNextMonth = Date.daysInMonth(nextY, nextM);
                var day = this.getDate();
                if (day > daysInNextMonth) {
                    day = daysInNextMonth;
                }
                return new Date(nextY, nextM, day);
            };
            // 再将Date类型的时间增加指定月份
            var nowDate = date.addMonth(addMonthNum);   //date格式的时间类型
            Date.prototype.format = function (format) {
                var date = {
                    "M+": this.getMonth() + 1,
                    "d+": this.getDate(),
                    "h+": this.getHours(),
                    "m+": this.getMinutes(),
                    "s+": this.getSeconds(),
                    "q+": Math.floor((this.getMonth() + 3) / 3),
                    "S+": this.getMilliseconds()
                };
                if (/(y+)/i.test(format)) {
                    format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
                }
                for (var k in date) {
                    if (new RegExp("(" + k + ")").test(format)) {
                        format = format.replace(RegExp.$1, RegExp.$1.length == 1
                            ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
                    }
                }
                return format;
            };
            // 最后将Date类型的时间在转化为字符串类型
            // var nowStr = nowDate.format('yyyy-MM-dd hh:mm:ss');   //指定字符串格式的时间类型
            var nowStr = nowDate.format('yyyy-MM-dd')
            return nowStr
        },
        compareDate(time1, time2) {
            function compareTime(startdate, enddate) {
                var date1 = startdate;
                var date2 = enddate;
                if (Date.parse(date1) < Date.parse(date2)) {
                    return '<'
                } else if (Date.parse(date1) > Date.parse(date2)) {
                    return '>'
                } else {
                    return '='
                }
            }
            return compareTime(time1, time2)
        },
        getTodayDate() { // 格式：yyyy-MM-dd
            let date = new Date(),
                year = date.getFullYear(), //获取完整的年份(4位)
                month = date.getMonth() + 1, //获取当前月份(0-11,0代表1月)
                strDate = date.getDate() // 获取当前日(1-31)
            if (month < 10) month = `0${month}` // 如果月份是个位数，在前面补0
            if (strDate < 10) strDate = `0${strDate}` // 如果日是个位数，在前面补0
            return `${year}-${month}-${strDate}`
        },
	}
};